package ar.edu.itba.cg.model;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;

import ar.edu.itba.cg.Bowling;

import com.jme.scene.Node;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.model.converters.MaxToJme;

public class FactoryModel {

	private static int BALL=0;
	private static int PIN=1;
	
	private static Node loadModel(int index) {
		Node model = null;
		try {
			MaxToJme C1 = new MaxToJme();
			ByteArrayOutputStream BO = new ByteArrayOutputStream();
			URL maxFile = Bowling.class.getClassLoader().getResource(
					"resources/Bowliing(3dmax)-new2.3DS");
			C1.convert(new BufferedInputStream(maxFile.openStream()), BO);
			model = (Node) BinaryImporter.getInstance().load(
					new ByteArrayInputStream(BO.toByteArray()));
		} catch (IOException e) {
			System.out.println("Could not load the Pin");
		}
		
		return (Node)model.getChild(index);
		
		
	}
	
	public static Node loadBall(){
		return loadModel(BALL);
	}
	
	public static Node loadPin(){
		return loadModel(PIN);		
	}

}
